<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>css-task1</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<style>
			html,
			body {
				width: 100%;
				height: 100%;
				padding: 0;
				margin: 0;
			}
			
			.container {
				max-width: 500px;
				margin: 20px auto;
			}
			
			ul {
				display: flex;
				flex-wrap: wrap;
				margin: 0;
				padding: 0;
			}
			
			ul>li {
				list-style-type: none;
				width: 30%;
				height: 0;
				padding-bottom: 30%;
				flex-grow: 3;
				margin: 1.5%;
				background-color: #ffa600;
				border-radius: 15%;
			}
			
			.container>div {
				width: 98%;
				height: 30px;
				line-height: 30px;
				background-color: #fff;
				border: 1px solid #ffa600;
				border-radius: 10px;
				margin: 20px auto 0;
				margin-top: 20px;
				text-align: center;
				color: #ffa600;
			}
			
			.container>div:hover {
				color: #fff;
				background-color: #ffa600;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<ul>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
			</ul>
			<div id="start">点击开始</div>
			<div id="end">点击结束</div>
		</div>
		<script>
			(function() {
				var lis = document.getElementsByTagName('li');
				var start = document.getElementById('start');
				var end = document.getElementById('end');
				var Num = Math.ceil(Math.random() * 9);

				var rgbColor = function() {
					var r = (Math.random() * 256 | 0);
					var g = (Math.random() * 256 | 0);
					var b = (Math.random() * 256 | 0);
					console.log("r=" + r);
					console.log("g=" + g);
					console.log("b=" + b);

					return "rgb(" + r + "," + g + "," + b + ")";
				}

				var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
				var result = [];
				var ranNum = 3;
				function getArray(){
//					var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
//					var result = [];
//					var ranNum = 3;
					for(var i = 0; i < ranNum; i++) {
						var ran = Math.floor(Math.random() * (arr.length - i));
						result.push(arr[ran]);
						arr[ran] = arr[arr.length - i - 1];
					};
					

				}
				
				function changeC() {
					getArray();
					for(var i = 0; i < arr.length; i++) {
						for(var j = 0; j < ranNum; j++) {
							if(result[j] == i) {
								lis[i].style.backgroundColor = rgbColor();
							} else {

							}
						}
					}
				}
				start.onclick = function() {
					//					var oNum = Math.ceil(Math.random() * 9);
					//					lis[oNum].style.backgroundColor = rgbColor();
					changeC()

				}
				end.onclick = function() {
					console.log('end')
				}
			}());
		</script>
	</body>

</html>